#include <iostream>
#include <string>
#include <functional>
#include "log.hpp"
#include "TcpServer.hpp"
#include "Protocal.hpp"


void ResquestTest();
void ResponseTest();

void Usage()
{
    std::cout << "\n\r" << "[Usage]:prot" <<"\n" << std::endl; 

}

int main(int argc ,char* argv[])
{ 

    if(argc != 2)
    {
        Usage();
        return -1;
    }

    // ResquestTest();
    // ResponseTest();

    lg(INFO,"Server start");
    
    ServerCal cal;
    std::string port_1 = argv[1];
    uint16_t port = std::stoi(port_1);

    TcpServer* tsur = new TcpServer(port,std::bind(&ServerCal::Calculator, &cal, std::placeholders::_1));
    tsur->Init();
    tsur->Start();


    return 0;
}

void ResponseTest()
{
    
    Response rp(222,1);
    std::string s;
    rp.Serialize(&s);
    std::cout << s << std::endl;

    auto pack = Encode(s);
    std::cout << pack <<std::endl;
    std::string con;
    bool r = Decode(pack,&con);
    std::cout << con << std::endl; 

    Response tmp;
    tmp.Deserialize(con);
    tmp.Print();
}

void ResquestTest()
{
    Requset req(123, '+', 456);
    std::string s;
    req.Serialize(&s);
    std::cout << s << std::endl;

    std::string pack;
    pack = Encode(s);
    std::cout << pack << std::endl;

    std::string con;
    auto r = Decode(pack, &con);
    std::cout << con << std::endl;
    Requset temp;
    temp.Deserialize(con);
    
    //std::cout << "x " << temp.x_ << " y " << temp.y_ << " op " << temp.op_ << std::endl;
    temp.Print() ;
}